<template>
  <div>
    <div class="common_form_search">
      <el-form
        ref="searchForm"
        :inline="true"
        :model="searchForm"
      >
        <el-form-item label="订单编号">
          <el-input
            style="width:220px"
            v-model="searchForm.order_id"
            placeholder="请输入订单编号"
            clearable
            @input="val=>changeNumberInput(val)"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户姓名">
          <el-input
            v-model="searchForm.user_name"
            placeholder="请输入用户姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input
            v-model="searchForm.user_mobile"
            placeholder="请输入手机号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="供应商名称">
          <el-input
            v-model="searchForm.shopname"
            placeholder="请输入供应商名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="使用时间">
          <my-date-picker ref="myDatePicker"></my-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            @click="search()"
          >查询</el-button>
          <el-button
            size="small"
            @click="reset()"
          >重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider></el-divider>
    <div class="flex align-center table-top-btns">
      <h5 class="flex align-center">
        <svg-icon
          style="margin-right:15px"
          icon-class="list"
          :size="15"
        />数据列表
      </h5>
    </div>
    <el-table
      :data="tableData"
      border
    >
      <el-table-column
        align="center"
        prop="id"
        width="60"
        label="ID"
      />
      <el-table-column
        align="center"
        width="190"
        label="订单编号"
      >
        <template slot-scope="scope">
          <span
            class="blue-font pointer"
            @click="goToOrder(scope.row.trade_no)"
          >{{scope.row.trade_no}}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="user_name"
        label="用户名"
      />
      <el-table-column
        align="center"
        prop="user_idcard"
        label="用户身份证号"
      />
      <el-table-column
        align="center"
        prop="user_mobile"
        label="用户手机号"
      />
      <el-table-column
        align="center"
        prop="shopname"
        label="供应商名称"
      />
      <el-table-column
        align="center"
        prop="risk_report_url"
        width="150"
        label="报告地址"
      >
        <template slot-scope="scope">
          <span
            class="blue-font pointer"
            @click="checkUrl(scope.row.risk_report_url ? $globalObj.imgBaseUrl + scope.row.risk_report_url : '')"
          >查看报告</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="create_time"
        label="查询时间"
      />
    </el-table>
    <custom-page
      ref="customPage"
      :total="total"
      @getList="getList"
    ></custom-page>
  </div>
</template>

<script>
import myDatePicker from "@/components/myDatePicker";
import customPage from "@/components/customPage";
import { riskUseList } from "@/api/data";
export default {
  components: { myDatePicker, customPage },
  data() {
    return {
      searchForm: {
        order_id: '',
        create_time: '',
        user_mobile: '',
        user_name: ''
      },
      tableData: [],
      total: 0
    }
  },
  methods: {
    checkUrl(url) {
      if (url) {
        window.open(url);
      } else {
        this.$message.warning("暂无可查看报告");
        return;
      }
    },
    goToOrder(orderId) {
      if (orderId) {
        this.$router.push({ name: 'orderList', params: { orderId } });
      }
    },
    // 查询
    search() {
      const pickerVal = this.$refs.myDatePicker.getVal();
      if (pickerVal !== 'error') {
        this.searchForm.create_time = pickerVal;
        this.$refs.customPage.page = 1;
        this.getList();
      }
    },
    // 重置
    reset() {
      if (this.$refs.myDatePicker) {
        this.$refs.myDatePicker.reset();
      }
      this.searchForm = {
        order_id: '',
        create_time: '',
        user_mobile: '',
        user_name: ''
      };
      this.getList();
    },
    changeNumberInput(value) {
      const pattern = /^[1-9][0-9]*$/
      if (!pattern.test(value)) {
        // input 框绑定的内容为空
        this.searchForm.order_id = ''
      }
    },
    getList() {
      const { page, pageSize } = this.$refs.customPage;
      riskUseList({
        page,
        pageSize,
        ...this.searchForm
      }).then(res => {
        const { data, total } = res;
        this.tableData = data || [];
        this.total = total || 0;
      })
    }
  },
  mounted() {
    this.getList();
  }
}
</script>

<style lang="scss" scoped>
</style>
